package com.chinatgl.tglec;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Toast;

import com.chinatgl.latte.app.Latte;
import com.chinatgl.latte.delegates.LatteDelegate;
import com.chinatgl.latte.net.RestClient;
import com.chinatgl.latte.net.callback.IError;
import com.chinatgl.latte.net.callback.IFailure;
import com.chinatgl.latte.net.callback.ISuccess;

import java.util.HashMap;
import java.util.WeakHashMap;

/**
 * 文件描述:
 * 作者: Created by 杨伟乔 on 2017/8/7 0007.
 * 版本号: 1.0
 */

public class ExampleDelegate extends LatteDelegate {

    @Override
    public Object setLayout() {
        return R.layout.delegate_example;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        testRestClient();
    }


    private void testRestClient() {

        WeakHashMap<String, Object> map = new WeakHashMap<>();
        RestClient.builder()
                .url("http://www.imooc.com/")
                .params(map)
                .loader(getContext())
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        System.out.println("onSuccess:" + response);
                    }
                })
                .fail(new IFailure() {
                    @Override
                    public void onFailure() {
                        System.out.println("onFailure:");

                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        System.out.println("onError:" + code + "---" + msg);

                    }
                })

                .build()
                .get();
    }
}
